#!/bin/sh

#define route
route1="/usr/bin/netcare/"
route2="/usr/bin/"
if [ $2 ];then
route1=$2
fi
if [ $3 ];then
route2=$3
fi

#download Netcare
scp -r root@$1:$route1 $route2

#download mono-2.0-service and install
sudo rpm -Uvh "$route2"netcare/tool/*.rpm 

#write init
echo "#!/bin/sh
#chkconfig: 235 98 01
### BEGIN INIT INFO
# provides              netcare_init_RedFlag
# Required-Start:	$"network" $"remote_fs" haldaemon
# Should-Start:		
# Required-Stop:	$"network" $"remote_fs" haldaemon
# Should-Stop:		
# Default-Start:	2 3 5
# Default-Stop:	
# description:          mono netcare
### END INIT INFO
start(){ 
nohup mono "${route2}"netcare/Netcare.Web.Host.Console.exe &
echo  "service Netcare is started..."  
}     
stop(){   
sudo killall mono
echo  "service Netcare is stoped..."  
}  
  
case $"1" in   
start)   
start   
;;   
stop)   
stop   
;;   
*)   
echo "error choice ! please input start or stop";;   
esac   
exit 0" > /etc/init.d/netcare_init_RedFlag
chmod +x /etc/init.d/netcare_init_RedFlag #add netcare to run

#create connect in different run level
sudo chkconfig --add netcare_init_RedFlag

#start netcare
nohup mono "${route2}:netcare/Netcare.Web.Host.Console.exe &

exit 1